#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>

//模拟柔性数组
struct S
{
	int a;
	int* arr;
};

int main()
{
	//开辟空间
	struct S* s = (struct S*)malloc(sizeof(struct S));
	if (s == NULL)
	{
		perror("malloc");
		return 1;
	}
	s->arr = (int*)calloc(5, sizeof(int));
	if (s->arr == NULL)
	{
		perror("calloc");
		return 1;
	}
	//使用
	s->a = 100;
	for (int i = 0;i < 5;i++)
	{
		s->arr[i] = i + 1;
	}
	//调整大小
	int* ptr = (int*)realloc(s->arr, 10 * sizeof(int));
	if (ptr == NULL)
	{
		perror("realloc");
		return 1;
	}
	s->arr = ptr;
	ptr = NULL;
	//重新使用
	for (int i = 5;i < 10;i++)
	{
		s->arr[i] = i + 1;
	}
	for (int i = 0;i < 10;i++)
	{
		printf("%d ",s->arr[i]);
	}
	//释放
	free(s->arr);
	s->arr = NULL;
	free(s);
	s = NULL;
	return 0;
}